package com.ddone.controller;

import com.ddone.pojo.dto.UserDto;
import jakarta.annotation.Resource;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

/**
 * @author ddone
 * @date 2024/5/14-09:44
 */
@RestController
public class ProduceController {

    @Resource
    private KafkaTemplate<String,Object> kafkaTemplate;

    @GetMapping("/send")
    public String send(){
        // 生产者发送消息
        kafkaTemplate.send("spring-test-topic", "hello kafka~~~~~");
        return "send: "+ LocalDateTime.now();
    }

    @GetMapping("/obj")
    public String object(){
        UserDto userDto = UserDto.builder().age(20).mobile("123100080").name("ddone").build();
        // 生产者发送消息
        kafkaTemplate.send("spring-test-topic", userDto);
        return "send: "+ LocalDateTime.now();
    }
}
